%%%-----------------------------------
%%% @Module  : pt_21
%%% @Author  : mxb
%%% @Created : 2016.09.19
%%% @Description: 21 飞禽走兽
%%%-----------------------------------
-module(pt_21).  
-export([read/2, write/2]).   
-include("common.hrl").
-include("proto_all.hrl").

%% ====================================================================
%% Internal functions
%% ====================================================================

%%
%%客户端 -> 服务端 ----------------------------
%%

%% 21000 请求进入活动
read(21000, Bin) ->
	{Data, _} = proto_read:unpack(c2s_enter_fowlsbeasts, Bin),
	{c2s_enter_fowlsbeasts, UID} = Data,
	{ok, [UID]};

%% 21001 退出活动
read(21001, Bin) ->
	{Data, _} = proto_read:unpack(c2s_leave_fowlsbeasts, Bin),
	{c2s_leave_fowlsbeasts, UID} = Data,
	{ok, [UID]};

%% 21002 押注
read(21002, Bin) ->
	{Data, _} = proto_read:unpack(c2s_fb_make_bet, Bin),
	{c2s_fb_make_bet, BetList} = Data,
	{ok, [BetList]};

%% 21004申请上庄
read(21004, Bin) ->
	{Data, _} = proto_read:unpack(c2s_apply_for_dealer, Bin),
	{c2s_apply_for_dealer, UID, Coin} = Data,
	{ok, [UID, Coin]};

%% 21005 下庄(通知玩家下庄)
read(21005, Bin) ->
	{Data, _} = proto_read:unpack(c2s_not_be_dealer, Bin),
	{c2s_not_be_dealer, UID} = Data,
	{ok, [UID]};

%% 21012 获取押注列表
read(21012, Bin) ->
	{Data, _} = proto_read:unpack(c2s_fb_bet_list, Bin),
	{c2s_fb_bet_list, UID} = Data,
	{ok, [UID]};

%% 21013 获取申请上庄列表
read(21013, Bin) ->
	{Data, _} = proto_read:unpack(c2s_fb_dealer_apply_list, Bin),
	{c2s_fb_dealer_apply_list, UID} = Data,
	{ok, [UID]};

%% 21014 聊天
read(21014, Bin) ->
	{Data, _} = proto_read:unpack(c2s_fb_face_talk, Bin),
	{c2s_fb_face_talk, FaceId, Phrase} = Data,
	{ok, [FaceId, Phrase]};

read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_21 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%% 服务端 -> 客户端 ----------------------------
%%

%% 21000 请求进入活动返回
write(21000, [Seq, RecordData]) ->
	%%io:format("~n===write=======21000===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_enter_fowlsbeasts, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21000, Data)};

%% 21001 退出活动
write(21001, [Seq, RecordData]) ->
	%%io:format("~n===write=======21001===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_leave_fowlsbeasts, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21001, Data)};

%% 21002 押注
write(21002, [Seq, RecordData]) ->
	%%io:format("~n===write=======21002===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_fb_make_bet, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21002, Data)};

%% 21003 押注广播
write(21003, [Seq, RecordData]) ->
	%%io:format("~n===write=======21003===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_fb_make_bet_cast, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21003, Data)};

%% 21004 申请上庄
write(21004, [Seq, RecordData]) ->
	%%io:format("~n===write=======21004===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_apply_for_dealer, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21004, Data)};

%% 21005 下庄(通知玩家下庄)
write(21005, [Seq, RecordData]) ->
	%%io:format("~n===write=======21005===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_not_be_dealer, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21005, Data)};

%% 21006 广播活动状态
write(21006, [Seq, RecordData]) ->
	%%io:format("~n===write=======21006===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_fowlsbeasts_state_cast, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21006, Data)};

%% 21007 广播连庄提示
write(21007, [Seq, RecordData]) -> 
	%%io:format("~n===write=======21007===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_remaining_dealer_cast, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21007, Data)};

%% 21008 开奖
write(21008, [Seq, RecordData]) ->
	%%io:format("~n===write=======21008===========RecordData:~p========~n", [RecordData]),

	MsgPack = proto_write:pack(s2c_fb_draw_reward, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21008, Data)};

%% 21009 结算
write(21009, [Seq, RecordData]) ->
	%%io:format("~n===write=======21009===========RecordData:~p========~n", [RecordData]),

	MsgPack = proto_write:pack(s2c_fb_give_reward, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21009, Data)};

%% 21010 广播成为庄家
write(21010, [Seq, RecordData]) ->
	%%io:format("~n===write=======21010===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_be_dealer_cast, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21010, Data)};

%% 21011 广播当前上庄申请人数
write(21011, [Seq, RecordData]) ->
	%%io:format("~n===write=======21011===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_apply_dealer_num_cast, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21011, Data)};

%% 21012 广播当前上庄申请人数
write(21012, [Seq, RecordData]) ->
	%%io:format("~n===write=======21012===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_fb_bet_list, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21012, Data)};

%% 21013 获取申请上庄列表
write(21013, [Seq, RecordData]) ->
	%%io:format("~n===write=======21012===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_fb_dealer_apply_list, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21013, Data)};

%% 21014 聊天
write(21014, [Seq, RecordData]) ->
	%%io:format("~n===write=======21014===========RecordData:~p========~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_fb_face_talk, RecordData),
	Data = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(21014, Data)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_21 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.